package com.huayue.dao;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.huayue.entity.RoomProductType;
import com.huayue.util.PageHelper;
import com.mysql.DBHelper;

/**
 * 房间商品类型（未用）
 */
@Component
public class RoomProductTypeDao implements BaseDao<RoomProductType> {
    @Override
    public int insert(RoomProductType entity) {
        return DBHelper.executeUpdate("insert into room_product_type (name,is_deleted) values(?,0)", entity.getName());
    }

    @Override
    public int update(RoomProductType entity) {
        return DBHelper.executeUpdate("update room_product_type set name=? , is_deleted=? where id=?", entity.getName(),
            entity.getIs_deleted(), entity.getId());
    }

    @Override
    public int delete(RoomProductType entity) {
        return DBHelper.executeUpdate("update room_product_type set is_deleted=1 where id=?", entity.getId());
    }

    @Override
    public List<Map<String, Object>> findAll(Object... obj) {
        return DBHelper.executeQuery("select * from room_product_type");
    }

    @Override
    public List<Map<String, Object>> findPage(PageHelper page, Object... obj) {
        RoomProductType room_product_type = (RoomProductType)obj[0];
        String sql = "select * from room_product_type where 1=1 and is_deleted=0 ";
        if (room_product_type.getName() != null && !"".equals(room_product_type.getName())) {
            sql += " and name like '%" + room_product_type.getName() + "%' ";
        }
        return DBHelper.executeQuery(sql + " limit ?,?", page.getBegin(), page.getPageSize());
    }

    @Override
    public Map<String, Object> findOne(RoomProductType entity) {
        return DBHelper
            .executeQuery("select * from room_product_type where 1=1 and is_deleted=0 and id=?", entity.getId()).get(0);
    }

    @Override
    public int count(Object... obj) {
        RoomProductType room_product_type = (RoomProductType)obj[0];
        String sql = "select count(*) counts  from room_product_type where 1=1 and is_deleted=0 ";
        if (room_product_type.getName() != null && !"".equals(room_product_type.getName())) {
            sql += " and name like '%" + room_product_type.getName() + "%' ";
        }
        return Integer.valueOf(DBHelper.executeQuery(sql).get(0).get("counts").toString());
    }
}
